package com.cf.studiomanage.mapper;

import com.cf.studiomanage.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    @Insert("INSERT INTO user(username, password, email, phone, role, status) VALUES(#{username}, #{password}, #{email}, #{phone}, 'USER', 'ACTIVE')")
    int register(User user);

    @Select("SELECT * FROM user WHERE (email = #{email} OR phone = #{phone}) AND password = #{password} AND status = 'ACTIVE'")
    User login(@Param("email") String email, @Param("phone") String phone, @Param("password") String password);

    @Select("SELECT * FROM user WHERE id = #{id}")
    User getById(Long id);

    @Update("UPDATE user SET username = #{username}, phone = #{phone}, avatar_url = #{avatarUrl}, introduction = #{introduction}, skill_tags = #{skillTags} WHERE id = #{id}")
    int updateProfile(User user);

    @Update("UPDATE user SET password = #{newPassword} WHERE id = #{id}")
    int updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword);
}
